package pattern.iterator;

import java.util.List;

// 迭代器接口实现类
public class IteratorImpl<T> implements Iterator<T> {
    private List<T> list;
    private Integer cursor;
    private T element;

    public IteratorImpl(List<T> list) {
        this.list = list;
    }

    public IteratorImpl() {
    }

    @Override
    public Boolean hasNext() {
        return cursor < list.size();
    }

    @Override
    public T next() {
        element = list.get(cursor);
        cursor++;
        return element;
    }
}
